package second.backtracking;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;

public class Solution14 {
    List<List<Integer>> res = new ArrayList<>();

    List<Integer> tmp = new ArrayList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        back(0, nums);
        return res;
    }

    public void back(int index, int[] nums) {
        if (tmp.size() >= 2) {
            res.add(new ArrayList<>(tmp));
            return;
        }
        HashSet<Integer> set = new HashSet<>();
        for (int i = index; i < nums.length; i++) {
            if (set.contains(nums[i])) continue;
            if (tmp.isEmpty() || nums[i] >= tmp.get(tmp.size() - 1)) {
                tmp.add(nums[i]);
                set.add(nums[i]);
                back(i + 1, nums);
                tmp.remove(tmp.size() - 1);
            }
        }
    }

}
